package com.agileai.pm.module.base.handler;

import java.util.List;

import com.agileai.domain.DataParam;
import com.agileai.domain.DataRow;
import com.agileai.hotweb.controller.core.StandardListHandler;
import com.agileai.hotweb.domain.FormSelectFactory;
import com.agileai.hotweb.domain.core.User;
import com.agileai.hotweb.renders.LocalRenderer;
import com.agileai.hotweb.renders.ViewRenderer;
import com.agileai.pm.cxmodule.ProjectInfoManage;
import com.agileai.pm.domain.Consts;
import com.agileai.pm.domain.Project;

public class ProjectInfoManageListHandler
        extends StandardListHandler {
    public ProjectInfoManageListHandler() {
        super();
        this.editHandlerClazz = ProjectInfoManageEditHandler.class;
        this.serviceId = buildServiceId(ProjectInfoManage.class);
    }
    
    public ViewRenderer prepareDisplay(DataParam param){
		mergeParam(param);
		initParameters(param);
		this.setAttributes(param);
		User user = (User)this.getUser();
		param.put("PI_CREATE_PEOPLE",user.getUserId());
		List<DataRow> rsList = getService().findRecords(param);
		this.setRsList(rsList);
		processPageAttributes(param);
		return new LocalRenderer(getPage());
	}

    protected void processPageAttributes(DataParam param) {
    	setAttribute("PI_TYPE",FormSelectFactory.create("PI_TYPE").addSelectedValue(param.get("PI_TYPE")));
        initMappingItem("PI_TYPE",FormSelectFactory.create("PI_TYPE").getContent());
    	Project project = (Project)this.getSessionAttribute(Consts.ProjectSessionKey);
		this.setAttribute("projectId", project.getProjectId());
    }

    protected void initParameters(DataParam param) {
        initParamItem(param, "PI_NAME", "");
        initParamItem(param, "PI_TYPE", "");
    }

    protected ProjectInfoManage getService() {
        return (ProjectInfoManage) this.lookupService(this.getServiceId());
    }
}
